include grid

mixin form-group(label)
  .form-group&attributes(attributes): .lr-grid
    .left.text-right: label.control-label #{label}
    .right: block

mixin form-grid(label, cols)
  +grid(cols): .lr-grid
    .left.text-right.inline-block: label.control-label #{label}
    .right.inline-block: block

//  水平表单
mixin form(name)
  form.form-horizontal(name="#{name}")&attributes(attributes)
    block
//  搜索表单
mixin searchForm(name)
  form.form-inline(name="#{name}" novalidate="novalidate" disable-dynamic-validation)&attributes(attributes)
    block
// 配合form使用。默认的formGroup, formGroup情况比较多，难封装，遇到时可在页面上自行添加覆盖该mixin
mixin formGroup(label, labelGrid, contentGrid)
  .form-group&attributes(attributes)
    +grid(labelGrid)(class="text-right"): label.control-label #{label}
    +grid(contentGrid): block
// 配合searchForm使用
mixin formGrid(label, labelGrid, contentGrid)
  +grid(labelGrid)(class="text-right")
    label #{label}
  +grid(contentGrid)&attributes(attributes)
    block

mixin text(obj, field)
  +input(obj, field)(type="text")&attributes(attributes)

mixin password(obj, field)
  +input(obj, field)(type="password")&attributes(attributes)

mixin radio(obj, field)
  +input(obj, field)(type="radio")&attributes(attributes)

mixin checkbox(obj, field)
  +input(obj,field)(type="checkbox" class="width-auto height-inherit")&attributes(attributes)

mixin file(obj, field)
  +input(obj,field)(type="file")&attributes(attributes)

mixin textarea(obj, field)
  if field
    textarea.form-control(id="#{obj.replace('.', '_')}_#{field.replace('.', '_')}", name="#{obj}.#{field}", ng-model="#{obj}.#{field}")&attributes(attributes)
  else
    textarea.form-control(id="#{obj}", name="#{obj}", ng-model="#{obj}")&attributes(attributes)

mixin select(obj, field)
  if field
    select.form-control(id="#{obj.replace('.', '_')}_#{field.replace('.', '_')}", name="#{obj}.#{field}", ng-model="#{obj}.#{field}")&attributes(attributes)
  else
    select.form-control(id="#{obj}", name="#{obj}", ng-model="#{obj}")&attributes(attributes)

mixin submit(label, express)
  button.btn.btn-primary(type="submit" ng-disabled="#{express}")&attributes(attributes) #{label}
mixin reset(label, obj)
  button.btn.btn-primary(type="reset")&attributes(attributes) #{label}
mixin cancel(label, obj)
  button.btn.btn-default(type="button")&attributes(attributes) #{label}
mixin primaryButton(label)
  button.btn.btn-primary(type="button")&attributes(attributes) #{label}
    block
mixin defaultButton(label)
  button.btn.btn-default(type="button")&attributes(attributes) #{label}
    block

// 以下mixin不建议外部调用
mixin input(obj, field)
  if field
    input.form-control(type="text" id="#{obj.replace('.', '_')}_#{field.replace('.', '_')}" name="#{obj}.#{field}" ng-model="#{obj}.#{field}")&attributes(attributes)
  else
    input.form-control(type="text" id="#{obj}" name="#{obj}" ng-model="#{obj}")&attributes(attributes)
